##Title:Appendix 1
##Date: 26 Sept 2023

```{r preparation}
library(tidyverse)

library(plm)
library(modelsummary)

dat <- read.csv("D:/Essex_PhD/3rd_year/Data for R&R/Replication_R1_20240918/replication_20231015.csv") 
unique(dat$gwno)
```

```{r t_test}
t.test(treat_pko_aid ~ treat_pko, dat, var.equal = TRUE)
t.test(treat_pko_aid ~ treat_aid, dat, var.equal = TRUE)

```


```{r Angola}
dat_Angola <- dat %>%
  filter(gwno == 540) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_Angola$catergory)
dat_Angola$catergory <- as.numeric(dat_Angola$catergory)
summary(dat_Angola$catergory)
table(dat_Angola$year)

dat_Angola.1 <- dat_Angola %>%
  dplyr::select(gid, year, gwno, troop.no:treat_aid, treat_pko_aid, catergory)

table(dat_Angola.1$catergory)
```

```{r Burundi}
dat_Burundi <- dat %>%
  filter(gwno == 516) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_Burundi$catergory)
dat_Burundi$catergory <- as.numeric(dat_Burundi$catergory)
summary(dat_Burundi$catergory)
table(dat_Burundi$year)
```

```{r DRC}
dat_DRC <- dat %>%
  filter(gwno == 490) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_DRC$catergory)
dat_DRC$catergory <- as.numeric(dat_DRC$catergory)
summary(dat_DRC$catergory)
table(dat_DRC$year)
```

```{r IvoryCoast}
dat_IvoryCoast <- dat %>%
  filter(gwno == 437) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_IvoryCoast$catergory)
dat_IvoryCoast$catergory <- as.numeric(dat_IvoryCoast$catergory)
summary(dat_IvoryCoast$catergory)
table(dat_IvoryCoast$year)

dat_IvoryCoast.1 <- dat_IvoryCoast %>%
  dplyr::select(gid, year, gwno, troop.no:treat_aid, treat_pko_aid, catergory)
```

```{r Liberia}
dat_Liberia <- dat %>%
  filter(gwno == 450) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_Liberia$catergory)
dat_Liberia$catergory <- as.numeric(dat_Liberia$catergory)
summary(dat_Liberia$catergory)
table(dat_Liberia$year)

dat_Liberia.1 <- dat_Liberia %>%
  dplyr::select(gid, year, gwno, troop.no:treat_aid, treat_pko_aid, catergory)
```

```{r SierraLeone}
dat_SierraLeone <- dat %>%
  filter(gwno == 451) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_SierraLeone$catergory)
dat_SierraLeone$catergory <- as.numeric(dat_SierraLeone$catergory)
summary(dat_SierraLeone$catergory)
table(dat_SierraLeone$year)

dat_SierraLeone.1 <- dat_SierraLeone %>%
  dplyr::select(gid, year, gwno, troop.no:treat_aid, treat_pko_aid, catergory)
```

```{r Sudan}
dat_Sudan <- dat %>%
  filter(gwno == 625) %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  ))


table(dat_Sudan$catergory)
dat_Sudan$catergory <- as.numeric(dat_Sudan$catergory)
summary(dat_Sudan$catergory)
table(dat_Sudan$year)

dat_Sudan.1 <- dat_Sudan %>%
  dplyr::select(gid, year, gwno, troop.no:treat_aid, treat_pko_aid, catergory)
```


```{r all}

table(dat$treat_pko_aid)

dat.1 <- dat  %>%
  mutate(catergory = case_when(
    treat_aid ==1 & treat_pko == 1 ~ "3",
    treat_aid ==0 & treat_pko == 1 ~ "2",
    treat_aid ==1 & treat_pko == 0 ~ "1",
    treat_aid ==0 & treat_pko == 0 ~ "0"
  )) %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))

table(dat.1$catergory)
dat.1$catergory <- as.numeric(dat.1$catergory)
summary(dat.1$catergory)
```

```{r country by country for osv}
dat_Angola.1 <- dat_Angola %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_Angola.1$treat_osv)

dat_Burundi.1 <- dat_Burundi %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_Burundi.1$treat_osv)

dat_DRC.1 <- dat_DRC %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_DRC.1$treat_osv)

dat_IvoryCoast.1 <- dat_IvoryCoast %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_IvoryCoast.1$treat_osv)

dat_Liberia.1 <- dat_Liberia %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_Liberia.1$treat_osv)

dat_SierraLeone.1 <- dat_SierraLeone %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_SierraLeone.1$treat_osv)

dat_Sudan.1 <- dat_Sudan %>%
  mutate(treat_osv = ifelse(osv >0, 1, 0))
table(dat_Sudan.1$treat_osv)

table(dat.1$treat_osv)
```

